package com.molichuxing.gateway.utils;

import java.util.ArrayList;
import java.util.List;

/**
 * The type Split boject utils.
 *
 * @author wanghualin
 * @date 2020 -05-08 13:27:58
 */
public class SplitObjectUtils {


    /**
     *
     * @param source  数组大小
     * @param factor   阀值
     * @return
     */
    public static List<List<String>> split(List<String> source,int factor) {
        List<List<String>> target = new ArrayList();
        if (source.size() <= factor) {
            target.add(source);
            return target;
        } else {
            for (int i = 0; i < source.size() / factor; i++) {
                List<String> list = source.subList(i * factor, factor + i * factor);
                target.add(list);
            }
            if (source.size() % factor != 0) {
                int i = (source.size() / factor);
                target.add(source.subList(i * factor, source.size()));
            }
            return target;
        }
    }
}
